//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "GaussLegendrePolynomial.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussJacobiPolynomial.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial () : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussLegendrePolynomial = NULL;
#endif
        _ppGaussLegendrePolynomial = new boost::shared_ptr<QuantLib::GaussLegendrePolynomial> (new QuantLib::GaussLegendrePolynomial ( ));
        SetGaussJacobiPolynomial (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussLegendrePolynomial));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial (boost::shared_ptr<QuantLib::GaussLegendrePolynomial>& childNative, Object^ owner) : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLegendrePolynomial = NULL;
#endif
	_ppGaussLegendrePolynomial = &childNative;
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussLegendrePolynomial));
}
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial (QuantLib::GaussLegendrePolynomial& childNative, Object^ owner) : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLegendrePolynomial = NULL;
#endif
	_ppGaussLegendrePolynomial = new boost::shared_ptr<QuantLib::GaussLegendrePolynomial> (&childNative);
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussLegendrePolynomial));
    _GaussLegendrePolynomialOwner = owner;
    _GaussJacobiPolynomialOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial (CGaussLegendrePolynomial^ copy) : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLegendrePolynomial = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussLegendrePolynomial = new boost::shared_ptr<QuantLib::GaussLegendrePolynomial> (copy->GetShared());
        _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussLegendrePolynomial));
    }
}
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial (System::Type^ t) : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLegendrePolynomial = NULL;
#endif
	if (!t->IsSubclassOf(CGaussLegendrePolynomial::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial (QuantLib::Handle<QuantLib::GaussLegendrePolynomial>& childNative, Object^ owner)  : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
	_phGaussLegendrePolynomial = &childNative;
	_ppGaussLegendrePolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussLegendrePolynomial>>(childNative.currentLink());
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussLegendrePolynomial));
    _GaussLegendrePolynomialOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial (QuantLib::Handle<QuantLib::GaussLegendrePolynomial> childNative)  : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
	_phGaussLegendrePolynomial = &childNative;
	_ppGaussLegendrePolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussLegendrePolynomial>>(childNative.currentLink());
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussLegendrePolynomial));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::CGaussLegendrePolynomial (QuantLib::GaussLegendrePolynomial childNative)  : CGaussJacobiPolynomial(CGaussLegendrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLegendrePolynomial = NULL;
#endif
	_ppGaussLegendrePolynomial = new boost::shared_ptr<QuantLib::GaussLegendrePolynomial> (new QuantLib::GaussLegendrePolynomial (childNative));
    _ppGaussJacobiPolynomial = new boost::shared_ptr<QuantLib::GaussJacobiPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussJacobiPolynomial> (*_ppGaussLegendrePolynomial));
}
#endif

Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::~CGaussLegendrePolynomial ()
{
    if (_ppGaussLegendrePolynomial != NULL)
    {
	    delete _ppGaussLegendrePolynomial;
        _ppGaussLegendrePolynomial = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::!CGaussLegendrePolynomial ()
{
    if (_ppGaussLegendrePolynomial != NULL)
    {
	    delete _ppGaussLegendrePolynomial;
    }
}
QuantLib::GaussLegendrePolynomial& Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::GetReference ()
{
    if (_ppGaussLegendrePolynomial == NULL) throw gcnew NativeNullException ();
	return **_ppGaussLegendrePolynomial;
}
boost::shared_ptr<QuantLib::GaussLegendrePolynomial>& Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::GetShared ()
{
    if (_ppGaussLegendrePolynomial == NULL) throw gcnew NativeNullException ();
	return *_ppGaussLegendrePolynomial;
}
QuantLib::GaussLegendrePolynomial* Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::GetPointer ()
{
    if (_ppGaussLegendrePolynomial == NULL) throw gcnew NativeNullException ();
	return &**_ppGaussLegendrePolynomial;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussLegendrePolynomial>& Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::GetHandle ()
{
	if (_phGaussLegendrePolynomial == NULL)
	{
		_phGaussLegendrePolynomial = new Handle<QuantLib::GaussLegendrePolynomial> (*_ppGaussLegendrePolynomial);
	}
	return *_phGaussLegendrePolynomial;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussLegendrePolynomial::HasNative () 
{
	return (_ppGaussLegendrePolynomial != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussLegendrePolynomial^ Cephei::QL::Math::Integrals::CGaussLegendrePolynomial_Factory::Create ()
{
    return gcnew CGaussLegendrePolynomial ();
}
